﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.IO;
using System.Data;
using System.Configuration;

namespace ResultsProducer
{
    /// <summary>
    /// Used to produce an "awards sheet" for the race. The "awards sheet" contains
    /// who the winners are to be given awards at the awards ceremony. 
    /// </summary>
    public class AwardsSheet
    {
        // Constructor that sets the RaceId.
        public AwardsSheet(int raceId)
        {
            this.raceId = raceId;
            
            cn = new SqlConnection(ConfigurationManager.ConnectionStrings["HuberRace"].ConnectionString);
            cn.Open();
        }

        // Returns a data table that's the overall men's sheet
        public DataTable OverallMensAwardsSheet()
        {
            var cmd = new SqlCommand(@"
                SELECT TOP 3 name,time,age,bib,gender
                FROM [ResultsWithAGForUSATF]
                WHERE 
                    raceId = @raceId
                    AND gender = @gender 
                ORDER BY place", cn);
            cmd.Parameters.AddWithValue("@raceId", raceId);
            cmd.Parameters.AddWithValue("@gender", 'm');

            var dt = new DataTable();
            dt.Load(cmd.ExecuteReader());
            
            return dt;
        }

        private int raceId;
        private string awardsSheetFilename;
        private StreamWriter sw;
        private SqlConnection cn;
    }
}
